import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

class HeaderWidget extends StatelessWidget {

  final double radius;

  final int unreadNum;

  final String url;


  HeaderWidget({this.radius, this.unreadNum = 0, this.url});

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.topRight,
      children: <Widget>[
        Container(
          padding: EdgeInsets.all(2.0),
          width: radius,
          height: radius,
          child: CachedNetworkImage(
            imageUrl: url,
            placeholder: new CircularProgressIndicator(),
            errorWidget: new Icon(Icons.error),
          ),
        ),
        Offstage(
          offstage: unreadNum == 0,
          child: Container(
            width: 18.0,
            height: 18.0,
            child: Center(child : Text(unreadNum.toString(),
              style: TextStyle(fontSize: 12.0, color: Colors.white),)),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(18.0),
                color: Colors.red
            ),
          ),
        )
      ],
    );
  }
}
